<template>
	<view>
		<!-- 引入二维码扫描组件 -->
		<mumu-get-qrcode @success='qrcodeSucess' @error="qrcodeError"></mumu-get-qrcode>

	</view>
</template>

<script>
	import mumuGetQrcode from '@/uni_modules/mumu-getQrcode/components/mumu-getQrcode/mumu-getQrcode.vue'
	import {
		$get,
		$post,
	} from '@/utils/request';
	export default {
		components: {
			mumuGetQrcode
		},
		props: {
			// 秀场ID
			fashionId: {
				type: [Number, String], // 支持数字或字符串类型
				required: true, // 标记为必填项（根据实际需求决定）
				default: null
			},
			// 日程ID
			scheduleId: {
				type: [Number, String],
				required: true,
				default: null
			}
		},
		data() {
			return {

			}
		},

		methods: {
			qrcodeSucess(data) {
				const resultID = data.split('|')[0];
				$post('/sys/webWriteOff/compare', {
					appointmentScheduleId: resultID,
					fashionId: this.fashionId,
					scheduleId: this.scheduleId
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							icon: 'success',
							title: res.message
						})

						// 三秒后触发scan-success事件
						setTimeout(() => {
							this.$emit('scan-success', res.data);
						}, 3000);

					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
						// 三秒后触发scan-success事件
						setTimeout(() => {
							this.$emit('scan-success', res.data);
						}, 3000);

					}
				})
			},
			qrcodeError(err) {
				console.log(err)
				uni.showModal({
					title: '摄像头授权失败',
					content: '摄像头授权失败，请检测当前浏览器是否有摄像头权限。',
					success: () => {
						uni.navigateBack({})
					}
				})
			}
		}
	}
</script>

<style>

</style>